CSS Full Course Day 3 [Hindi] πŸ’» | CSS Box Model πŸš€ | Mohit Decodes

πŸ“¦ CSS Tutorial – Day 3: CSS Box Model

Welcome to Day 3 of the CSS Full Course [Hindi] by Mohit Decodes! Today’s lesson covers the CSS Box Model, a fundamental concept to understand how elements are sized and spaced on a webpage.

πŸ”Ή What is the CSS Box Model?

Every HTML element is a rectangular box composed of four parts:

  1. Content β€” The actual text or media inside the box
  2. Padding β€” Space between the content and the border
  3. Border β€” The edge around the padding
  4. Margin β€” Space outside the border, separating the element from others

πŸ”Ή Visual Representation:

lua
CopyEdit
+---------------------------+
| Margin |
| +---------------------+ |
| | Border | |
| | +---------------+ | |
| | | Padding | | |
| | | +-----------+ | | |
| | | | Content | | | |
| | | +-----------+ | | |
| | +---------------+ | |
| +---------------------+ |
+---------------------------+

βš™οΈ CSS Properties Related to Box Model:

  1. width & height β€” size of content box
  2. padding β€” inner spacing
  3. border β€” thickness and style of border
  4. margin β€” outer spacing

πŸ“Œ Example Code:

css
CopyEdit
div.box {
width: 200px;
padding: 20px;
border: 5px solid #333;
margin: 15px;
background-color: lightblue;
}

πŸ’‘ Important Tips:

  1. By default, width and height apply only to the content area.
  2. Use box-sizing: border-box; to include padding and border within width/height.
  3. Proper use of margin and padding controls spacing between elements.